package PAT;

import java.util.ArrayList;
import java.util.Scanner;

class BiTreeNode {
    int value;
    BiTreeNode left, right;

    public BiTreeNode(int value) {
        this.value = value;
    }

    public BiTreeNode addNode(BiTreeNode node) {
        BiTreeNode root = this;
        while (true) {
            if (root.value < node.value) {
                if (root.right == null) {
                    root.right = node;
                    break;
                } else {
                    root = root.right;
                }
            }
            if (root.value >= node.value) {
                if (root.left == null) {
                    root.left = node;
                    break;
                } else {
                    root = root.left;
                }
            }
        }
        return node;
    }
}

public class PAT1043 {
    // 平衡二叉树的先序遍历顺序和插入顺序相同
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        BiTreeNode root = new BiTreeNode(scanner.nextInt());
        int[] values = new int[n];
        for (int i = 0; i < n - 1; i++) {
            int p = scanner.nextInt();
            values[i + 1] = p;
            root.addNode(new BiTreeNode(p));
        }
        ArrayList<Integer> preOrder = new ArrayList<>();
        preorder(root, preOrder);
        boolean isTrue = check(values, preOrder);
        if(isTrue){
            System.out.println("YES");
            postorder(root);
        }
    }

    private static void postorder(BiTreeNode root) {
        if(root==null) return;
        postorder(root.left);
        postorder(root.right);
        System.out.print(root.value+" ");
    }

    private static boolean check(int[] values, ArrayList<Integer> preOrder) {
        for (int i = 1; i < values.length; i++) {
            if (values[i] != preOrder.get(i)) return false;
        }
        return true;
    }

    private static void preorder(BiTreeNode root, ArrayList<Integer> preOrder) {
        if (root == null) return;
        preOrder.add(root.value);
        preorder(root.left, preOrder);
        preorder(root.right, preOrder);
    }
}
